package com.dgut.controller;

import com.dgut.entity.Record;
import com.dgut.util.ExcelUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin")
public class ExcelController {

    @RequestMapping("/excel")
    String generate(HttpServletResponse response, @RequestBody List<Record> list) {
        log.info("excel data={}", list);
        try {
            String result = ExcelUtil.writeExcel(response, list);
            log.info("excel ok");
            return result;
        } catch (IOException e) {
            e.printStackTrace();
            return "fail to write excel";
        }
    }
}
